package main
import "fmt"
//只有发送者可以关闭信道；向一个已经关闭的信道发送数据会引起恐慌
func fibonacci(n int, c chan int){
	x, y := 0, 1
	for i := 0; i < n; i++ {
		c <- x
		x, y = y, x+y
	}
	close(c)
	/*
		panic: send on closed channel
		goroutine 18 [running]:
	*/
	c <- 666
}
func main(){
	c := make(chan int, 10)
	go fibonacci(cap(c), c)
	for i := range c{
		fmt.Println(i)
	}
	/*
		0
		1
		1
		2
		3
		5
		8
		13
		21
		34
	*/
}